Message Hook Control v1.0.0.2 ReadMe.
Contents
Message Hook control v1.0 is an ActiveX control that allows
handling window messages sent to any windowed control or window
(form). It is especially useful in MS Visual Basic v4.0 where
there is no way to handle messages but those exposed by OLE
controls or forms. Although in the versions 5 and 6 You can write
callback functions and, thus, it is possible to implement window
subclassing in VB but it is rather complicated, whereas Message
Hook control lets to get it in a very simple way. Message Hook
control lets You specify a target window and messages (Windows
message IDs) , which are desired to be handled. It is also
possible to define a way when the message must be handled -
before, after or without being processed by default window
procedure.
- Message Hook control is lightweight (104K only!)
self-contained ActiveX control, i.e. it does not require any run-time
libraries like MFC DLLs.
- It implements windows subclassing to achieve a
possibility to process window messages rather then
hooks so it does not consume any additional windows resources.
- It is possible to define a way when the message must
be handled - before, after or without being processed by default window
procedure.
- You use a control per window (or per windowed
control).
- You can disable Message Hook at any time so the default
window procedure will be used, and You can enable it at
any time to override,extend or disable the default window
procedure.
-
Smaller size! Now it is 104K only, instead of 140K in
its initial version. The functionality is as before.
-
In designe mode MsgHook is displayed as fixed size
icon.
It is very simple to use Message Hook control.
- At design time, put Message Hook control on the form
which messages You want be able to process. If You want to handle messages of
a control put the Message Hook control an the form containing this control.
Set Enabled property to true to enable mesage handling.
- In You code, define message contants with windows message
IDs You want to handle. In VB, for example, define such a
constant in a module:
Public Const WM_GETMINMAXINFO = &H24
- Set hWnd property to a valid window handle. In
VB, for example, if You are going to handle form's
messages, write in Sub Form_Load:
MsgHook1.hWnd = hWnd
If You want to process a control's messages set hWnd property
of the Message Hook control to the control's hWnd property.
Generally, You can set hWnd property to any valid window handle.
- Add message IDs You wish to handle. You can add
as many message as You need but You can not add the same
message more than once.
MsgHook1.AddMessage WM_GETMINMAXINFO, mshEatMessage
- Use Message event procedure of the Message Hook
control to handle the message.
Private Sub MsgHook1_Message(ByVal MsgId As Long,
ByVal wParam As Long, ByVal lParam As Long,
ByVal MsgProcessing As Integer, MsgResult As Long)
Select Case MsgId
Case WM_GETMINMAXINFO:
'Event handling code goes here
End Select
End Sub
You can set MsgResult parameter if You wish to define a value
to be returned by windows procedure. This parameter is set by
default windows procedure if the message is postprocessed, is 1
if the message is eaten, and You can change this value. If the
message is preprocessed then the returned value likely will be
modified by the default window procedure called after Your
handler.
Note:
If You update
from build 1.0.0.0 or 1.0.0.1 to v1.0.0.2 you can get
an error message while opening a window containig MsgHook
control.
VB Users: If
this occurs then delete the control from the form and put it back
again, then save the form. This problem arises because the
way MsgHook control's properties are saved is now slightly
different.
Other
tools users: You probably will need to remove the control
from the container and put it back, and then
save.
It is also may
be necessary to recompile your projects that use MsgHook
control.
In the case you
can not recompile your project: continue using the previous
version.
Properties
- Property Enabled As Boolean
Returns/sets a value that determines whether the control
handles messages defined. If set to False, the
mesages are passed to the default window procedure rather
then to be handled by control, i.e. Message
event is not fired. Must be True to enable control to handle defined messages.
- Property hWnd As Long
property hWnd - Returns/sets window handle which messages
must be handled.
Methods
- Sub AddMessage(MsgId As Long, Processing
As Integer)
method AddMessage - adds a message to be processed. If
there message with the same MsgId already
exists, its Processing is updated.
- Function RemoveMessage(MsgId As Long) As
Boolean
Removes a message with given MsgId from the
processed messages list. Returns True upon success, False
if given MsgId is not found.
- Sub ClearMessageList()
Removes all message from the processed messages list.
Events
- Message(ByVal MsgId As Long, ByVal
wParam As Long, ByVal lParam As Long, ByVal MsgProcessing
As Integer, MsgResult As Long)
Occurs when a message captured by Message Hook control.
This event may occur before, after or without being
processed by window's original message procedure,
depending on message processing type set by AddMessage
method.
Parameters:
- ByVal MsgId As Long
Message ID being handled. In VB use Select
Case or If...Then structures to handle different messages in this event
procedure.
- ByVal wParam As Long
Corresponds to the first message parameter. Its
value meaning depend on the message You handle. See Windows API reference
for windows messages description.
- ByVal lParam As Long
Corresponds to the second message parameter. Its
value meaning depend on the message You handle. See Windows API reference
for windows messages description.
- ByVal MsgProcessing As Integer
Indicates the
processing type for the currently handled message.It is equal to one of
three message processing constants.
- ByRef MsgResult As Long
Set MsgResult parameter if You wish to
define a value to be returned by windows
procedure. This parameter is set by default
windows procedure if the message is
postprocessed, is 1 if the message is eaten, and
You can change this value. If the message is
preprocessed then the returned value likely will
be modified by the default window procedure
called after Your handler. The table below
summarizes the usage of this parameter:
MsgProcessing
value |
mshPreProcess |
mshPostProcess |
mshEatMessage |
MsgResult |
Read |
Read/Write |
Read, always 1 |
Enums
MessageProcessingEnums:
- Const mshPreProcess = 0.
Use this value to
handle a message before being processed by window's original message
procedure.
- Const mshPostProcess = 1
Use this value to
handle a message after being processed by window's original message procedure.
- Const mshEatMessage = 2
Use this value to handle a message without being
processed by window's original message procedure.
There are three examples for VB 4 that show how this control
may be used. These examles are also successfully tested with VB
6.0. Please feel free to copy and paste the code from these
examples.
MinMax
This sample uses Message Hook control to conrrol form's
minimal and manimal dimensions by processing WM_GETMINMAXINFO
message. Try to resize the form.
SysMenu
This sample uses Message Hook control to modify form's system
menu (Control Box) and handle its messages. Check
"About" item from the system menu.
SysTray
This sample uses Message Hook control to create a taskbar tray
notification area icon and handle all mouse events.
THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED
"AS IS" AND WITHOUT WARRANTIES AS TO PERFORMANCE OF
MERCHANTABILITY OR ANY OTHER WARRANTIES WHETHER EXPRESSED OR
IMPLIED. Because this product is a freeware no technical support
or troubleshooting is guaranteed, no responsibility for any
damage that may be caused by the use of this software. No bug fix
is guaranteed. You use this software on Your own risk!
Bug and problem reports
Please send to alexw@netvision.net.il
Alex Wainstein,
e-mail: alexw@netvision.net.il
Last updated: 23-Feb-1999